/**
 * Filename: SwitchMusicAdapter.java
 * @author  Firefly
 * @contact postfirefly@163.com
 * @time    2016/5/8 13:38
 */
package com.github.postsanf.yinian.adapter;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.github.postsanf.yinian.BaseApplication;
import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.activity.AlbumStatusActivity;
import com.github.postsanf.yinian.activity.InviteChooseActivity;
import com.github.postsanf.yinian.bean.YNAlbum;
import com.github.postsanf.yinian.bean.YNMusic;
import com.github.postsanf.yinian.constants.ACTIONs;
import com.github.postsanf.yinian.constants.CommonConstants;
import com.github.postsanf.yinian.constants.YNSingleton;
import com.github.postsanf.yinian.fragment.HomeAlbumFragment;
import com.github.postsanf.yinian.utils.ImageOptHelper;
import com.github.postsanf.yinian.utils.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

public class SwitchMusicAdapter extends RecyclerView.Adapter<SwitchMusicAdapter.ViewHolder>{
    private Context context;
    private List<YNMusic> datas;

    public SwitchMusicAdapter(Context context, List<YNMusic> datas) {
        this.context = context;
        this.datas = datas;
    }

    public  class ViewHolder extends RecyclerView.ViewHolder {
        RelativeLayout rl_music_view;					    // 列表View
        TextView    tv_music_duration;					    // 音乐时长
        TextView    tv_music_name;					        // 音乐名

        public ViewHolder(View itemView) {
            super(itemView);
            rl_music_view	= (RelativeLayout) itemView
                        .findViewById(R.id.rl_music_view);
            tv_music_duration = (TextView) itemView
                        .findViewById(R.id.tv_music_duration);
            tv_music_name = (TextView) itemView
                        .findViewById(R.id.tv_music_name);
        }

        public void bindData(final YNMusic listItems)
        {
            if (listItems != null)
            {
                tv_music_name.setText(listItems.getMusicName());
                tv_music_duration.setText(listItems.getMusicTempletID());
                // 点击列表
                rl_music_view.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // 设置选中状态并开始播放音乐
                    }
                });
            }
        }
    }

    private YNMusic getItem(int position) {
        return datas.get(position);
    }

    // 创建ViewHolder
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.yn_item_switch_music, parent, false);
        return new ViewHolder(convertView);
    }

    // 绑定数据到View
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        YNMusic listItems = getItem(position);
        holder.bindData(listItems);
        holder.itemView.setTag(listItems);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }
}
